package com.xbongbong.parent.explain;

import com.xbongbong.paas.field.FieldAttrEntity;
import com.xbongbong.paas.toolbox.exception.XbbException;
import com.xbongbong.paas.toolbox.wrap.UserVO;
import com.xbongbong.paas.util.ExplainUtil;
import com.xbongbong.parent.abstracts.AbstractFormExplainHandleName;
import com.xbongbong.pro.enums.errorcodes.SystemErrorCodeEnum;
import com.xbongbong.pro.formexplain.pojo.dto.HandlerExplainDTO;
import com.xbongbong.pro.formexplain.pojo.vo.HandlerExplainVO;
import com.xbongbong.saas.constant.BasicConstant;
import lombok.extern.log4j.Log4j2;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @author sunshaoxiang
 * @ClassName FormDataUpdateGetExplainHandler
 * @Description 表单数据  编辑页  获取字段回显名称，以及过滤不可见字段
 * @Date 2022/4/6 9:32
 * @Version 1.0
 **/
@Component
@Log4j2
public class FormDataUpdateGetExplainHandler extends AbstractFormExplainHandleName {

    @Override
    public HandlerExplainVO handleExplain(HandlerExplainDTO handlerExplainDTO) throws XbbException {
        HandlerExplainVO handlerExplainVO;
        try {
            List<FieldAttrEntity> explainList = handlerExplainDTO.getExplainList();
            handlerExplainVO = getExplainList(explainList, handlerExplainDTO);
            handleExplainDefaultLimit(handlerExplainVO, handlerExplainDTO);
        } catch (XbbException e) {
            throw e;
        } catch (Exception e) {
            log.error("FormDataUpdateGetExplainHandler.handleExplain处理字段中的部门、角色、用户等名称报错", e);
            throw new XbbException(SystemErrorCodeEnum.API_ERROR_100001, SystemErrorCodeEnum.API_ERROR_100001.getMsg());
        }
        return handlerExplainVO;
    }

    @Override
    protected void telephoneNumberMask(FieldAttrEntity entity, UserVO loginUser) {
        //设置了电话掩码后，编辑页隐藏电话信息
        if (ExplainUtil.isOpenTelephoneMask(entity, loginUser)) {
            entity.setVisible(BasicConstant.ZERO);
        }
    }
}
